package com.jwds.digital.bios.business.schedule.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.google.common.collect.Lists;
import com.jwds.digital.bios.business.core.constants.DispatchConstant;
import com.jwds.digital.bios.business.core.constants.RuleCodeConstant;
import com.jwds.digital.bios.business.core.enums.WarehouseClassification;
import com.jwds.digital.bios.business.core.infrastructure.dto.dispatch.DispatchParameterReqDTO;
import com.jwds.digital.bios.business.core.infrastructure.dto.dispatch.FiveBasicInformationReqDTO;
import com.jwds.digital.bios.business.core.infrastructure.dto.feign.BasicStockBinReqDTO;
import com.jwds.digital.bios.business.core.infrastructure.dto.feign.FlowBasicReqDTO;
import com.jwds.digital.bios.business.core.infrastructure.vo.feign.BasicStockBinRespVO;
import com.jwds.digital.bios.business.core.infrastructure.vo.feign.FlowBasicRespVO;
import com.jwds.digital.bios.business.core.utils.FeignResultUtil;
import com.jwds.digital.bios.business.integration.service.impl.L32BC06;
import com.jwds.digital.bios.business.rpc.feign.BasicStockBinFeign;
import com.jwds.digital.bios.business.rpc.feign.FlowBasicFeign;
import com.jwds.digital.bios.business.schedule.service.IScheduleTaskService;
import com.jwds.digital.bios.business.service.rule.DispatchRuleSortFactory;
import com.jwds.digital.bios.business.service.rule.DispatchRuleSortInterface;
import com.jwds.tdc.framework.cache.service.CacheService;
import com.jwds.tdc.framework.schedule.annotation.ScheduleRegister;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.kafka.connect.data.Decimal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @Author hesong
 */
@Slf4j
@Service
public class ScheduleTaskServiceImpl implements IScheduleTaskService {

    @Autowired
    DispatchRuleSortFactory dispatchRuleSortFactory;

    @Autowired
    private BasicStockBinFeign basicStockBinFeign;

    @Autowired
    private FlowBasicFeign flowBasicFeign;

    @Autowired
    private L32BC06 l32bc06;

    @Autowired
    private CacheService cacheService;
    private Map<String, Object> resourceInfo = new HashMap<>();
    private boolean isClosed = false;


    @Override
    public void dispatchMonitor() {

        // TODO  这里虚拟的规则编码，后续从相关规则表中查出
        List<String> ruleCodeList = Lists.newArrayList();
        ruleCodeList.add(RuleCodeConstant.STARTING_POLNT_POSITION_OF_RULES);
        ruleCodeList.add(RuleCodeConstant.RULE_STARTING_POINT_EQUIPMENT);
        ruleCodeList.add(RuleCodeConstant.RULE_ENDPOINT_POSITION);
        ruleCodeList.add(RuleCodeConstant.RULE_ENDPOINT_EQUIPMENT);
        ruleCodeList.add(RuleCodeConstant.TECHNOLOGICAL_PROCESS);
        ruleCodeList.add(RuleCodeConstant.IS_THE_CAR_IDLE);
        ruleCodeList.add(RuleCodeConstant.ROUTE_ENERGY_CONSUMPTION);
        ruleCodeList.add(RuleCodeConstant.WAREHOUSE_RETURN_MATERIAL);
    }


    /**
     * 预配料仓
     */
    @Override
    public void preIngredientWarehouse() {
        WarehouseClassification preconfiguration = WarehouseClassification.YPLC;
        if (preconfiguration.Preconfiguration()) {
            BasicStockBinReqDTO basicStockBinReqDTO = new BasicStockBinReqDTO();
            basicStockBinReqDTO.setBinCode(String.valueOf(WarehouseClassification.YPLC));
            List<BasicStockBinRespVO> listBaseStockBin = FeignResultUtil.getDataFromBaseResponse(basicStockBinFeign.list(basicStockBinReqDTO));
            ArrayList<DispatchParameterReqDTO> parameterReqDTOArrayList = new ArrayList<>();
            // 根据终点设备来查看流程
            for (BasicStockBinRespVO basicStockBinRespVO : listBaseStockBin) {
                DispatchParameterReqDTO dispatchParameterReqDTO = new DispatchParameterReqDTO();
                List<FiveBasicInformationReqDTO> fiveBasicInformationReqDTOList = new ArrayList<>();
                FiveBasicInformationReqDTO fiveBasicInformationReqDTO = new FiveBasicInformationReqDTO();
                // 根据出仓设备来查询流程
                FlowBasicReqDTO flowBasicReqDTO = new FlowBasicReqDTO();
                flowBasicReqDTO.setEndDeviceCode(basicStockBinRespVO.getDeviceIn());
                List<FlowBasicRespVO> flowBasicRespVOList = FeignResultUtil.getDataFromBaseResponse(flowBasicFeign.all(flowBasicReqDTO));
                // 终点仓
                dispatchParameterReqDTO.setSlot(basicStockBinRespVO);
                // 终点设备
                dispatchParameterReqDTO.setDeviceCodeList(flowBasicRespVOList.stream().map(FlowBasicRespVO::getEndDeviceCode).collect(Collectors.toList()));
                // 终点设备默认值
                if (flowBasicRespVOList != null && flowBasicRespVOList.size() > 0) {
                    fiveBasicInformationReqDTO.setDeviceTypeDefault(flowBasicRespVOList.get(0).getStartDeviceCode());
                }
                for (FlowBasicRespVO flowBasicRespVO : flowBasicRespVOList) {
                    // 流程线路
                    fiveBasicInformationReqDTO.setFlow(flowBasicRespVO);
                }
                // 起点设备
                fiveBasicInformationReqDTO.setDeviceCodeList(flowBasicRespVOList.stream().map(FlowBasicRespVO::getStartDeviceCode).collect(Collectors.toList()));
                // 起点设备默认值
                if (flowBasicRespVOList != null && flowBasicRespVOList.size() > 0) {
                    fiveBasicInformationReqDTO.setDeviceTypeDefault(flowBasicRespVOList.get(0).getStartDeviceCode());
                }
                // 根据入仓设备来起点位置
                List<BasicStockBinRespVO> flowBasicList = null;
                BasicStockBinReqDTO basicStockBin = new BasicStockBinReqDTO();
                for (String s : fiveBasicInformationReqDTO.getDeviceCodeList()) {
                    basicStockBin.setDeviceOut(s);
                    flowBasicList = FeignResultUtil.getDataFromBaseResponse(basicStockBinFeign.list(basicStockBin));
                }
                // 起点位置
                fiveBasicInformationReqDTO.setOtherSlotList(flowBasicList);
                // 仓标识
                dispatchParameterReqDTO.setSlotIdentification("1");
                fiveBasicInformationReqDTOList.add(fiveBasicInformationReqDTO);
                dispatchParameterReqDTO.setFlowList(fiveBasicInformationReqDTOList);
                parameterReqDTOArrayList.add(dispatchParameterReqDTO);
            }
            // 规则排序
            // 仓的可用时间
            DispatchRuleSortInterface handlerInstance = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.AVAILABLE_TIME);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList = handlerInstance.sortProcess(parameterReqDTOArrayList);
            // 查看刮板机是否空闲
            DispatchRuleSortInterface handlerInstance1 = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.IS_THE_CAR_IDLE);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList1 = handlerInstance1.sortProcess(dispatchParameterReqDTOList);
            // 根据流程来进行排序
            DispatchRuleSortInterface handlerInstance2 = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.ROUTE_ENERGY_CONSUMPTION);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList2 = handlerInstance2.sortProcess(dispatchParameterReqDTOList1);
            // 查看起点位置的料
            DispatchRuleSortInterface handlerInstance3 = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.WAREHOUSE_MATERIALS);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList3 = handlerInstance3.sortProcess(dispatchParameterReqDTOList2);
            // 仓容百分比到达上跟换终点料仓
            DispatchRuleSortInterface handlerInstance4 = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.HIGH_MATERIAL_LEVEL);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList4 = handlerInstance4.sortProcess(dispatchParameterReqDTOList3);
            // 将排序后的数据放入redis中
            cacheService.setString(DispatchConstant.REDIS_KEY+":"+WarehouseClassification.YPLC, JSONUtil.toJsonStr(dispatchParameterReqDTOList4));
        } else {
            throw new RuntimeException("非预配料仓，不支持该操作");
        }
    }

    /**
     * 块矿缓冲仓加仓
     */
    @Override
    public void dispatchBlockMine() {
        WarehouseClassification preconfiguration = WarehouseClassification.KKC;
        if (preconfiguration.BlockMineAdd()) {
            BasicStockBinReqDTO basicStockBinReqDTO = new BasicStockBinReqDTO();
            basicStockBinReqDTO.setBinCode(String.valueOf(WarehouseClassification.KKC));
            List<BasicStockBinRespVO> listBaseStockBin = FeignResultUtil.getDataFromBaseResponse(basicStockBinFeign.list(basicStockBinReqDTO));
            ArrayList<DispatchParameterReqDTO> parameterReqDTOArrayList = new ArrayList<>();
            // 根据终点设备来查看流程
            for (BasicStockBinRespVO basicStockBinRespVO : listBaseStockBin) {
                DispatchParameterReqDTO dispatchParameterReqDTO = new DispatchParameterReqDTO();
                List<FiveBasicInformationReqDTO> fiveBasicInformationReqDTOList = new ArrayList<>();
                FiveBasicInformationReqDTO fiveBasicInformationReqDTO = new FiveBasicInformationReqDTO();
                // 根据出仓设备来查询流程
                FlowBasicReqDTO flowBasicReqDTO = new FlowBasicReqDTO();
                flowBasicReqDTO.setEndDeviceCode(basicStockBinRespVO.getDeviceIn());
                List<FlowBasicRespVO> flowBasicRespVOList = FeignResultUtil.getDataFromBaseResponse(flowBasicFeign.all(flowBasicReqDTO));
                // 终点仓
                dispatchParameterReqDTO.setSlot(basicStockBinRespVO);
                // 终点设备
                dispatchParameterReqDTO.setDeviceCodeList(flowBasicRespVOList.stream().map(FlowBasicRespVO::getEndDeviceCode).collect(Collectors.toList()));
                // 终点设备默认值
                if (flowBasicRespVOList != null && flowBasicRespVOList.size() > 0) {
                    fiveBasicInformationReqDTO.setDeviceTypeDefault(flowBasicRespVOList.get(0).getStartDeviceCode());
                }
                for (FlowBasicRespVO flowBasicRespVO : flowBasicRespVOList) {
                    // 流程线路
                    fiveBasicInformationReqDTO.setFlow(flowBasicRespVO);
                }
                // 起点设备
                fiveBasicInformationReqDTO.setDeviceCodeList(flowBasicRespVOList.stream().map(FlowBasicRespVO::getStartDeviceCode).collect(Collectors.toList()));
                // 起点设备默认值
                if (flowBasicRespVOList != null && flowBasicRespVOList.size() > 0) {
                    fiveBasicInformationReqDTO.setDeviceTypeDefault(flowBasicRespVOList.get(0).getStartDeviceCode());
                }
                // 根据入仓设备来起点位置
                List<BasicStockBinRespVO> flowBasicList = null;
                BasicStockBinReqDTO basicStockBin = new BasicStockBinReqDTO();
                for (String s : fiveBasicInformationReqDTO.getDeviceCodeList()) {
                    basicStockBin.setDeviceOut(s);
                    flowBasicList = FeignResultUtil.getDataFromBaseResponse(basicStockBinFeign.list(basicStockBin));
                }
                // 起点位置
                fiveBasicInformationReqDTO.setOtherSlotList(flowBasicList);
                // 仓标识
                dispatchParameterReqDTO.setSlotIdentification("1");
                fiveBasicInformationReqDTOList.add(fiveBasicInformationReqDTO);
                dispatchParameterReqDTO.setFlowList(fiveBasicInformationReqDTOList);
                parameterReqDTOArrayList.add(dispatchParameterReqDTO);
            }
            // 规则排序
            // 仓的可用时间
            DispatchRuleSortInterface handlerInstance = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.AVAILABLE_TIME);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList = handlerInstance.sortProcess(parameterReqDTOArrayList);
            // 查看刮板机是否空闲
            DispatchRuleSortInterface handlerInstance1 = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.IS_THE_CAR_IDLE);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList1 = handlerInstance1.sortProcess(dispatchParameterReqDTOList);
            // 根据流程来进行排序
            DispatchRuleSortInterface handlerInstance2 = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.ROUTE_ENERGY_CONSUMPTION);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList2 = handlerInstance2.sortProcess(dispatchParameterReqDTOList1);
            // 查看起点位置的料
            DispatchRuleSortInterface handlerInstance3 = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.WAREHOUSE_MATERIALS);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList3 = handlerInstance3.sortProcess(dispatchParameterReqDTOList2);
            // 仓容百分比到达上跟换终点料仓
            DispatchRuleSortInterface handlerInstance4 = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.HIGH_MATERIAL_LEVEL);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList4 = handlerInstance4.sortProcess(dispatchParameterReqDTOList3);
            // 块矿缓冲仓加仓
            // 块矿缓冲仓的放仓流量大，进仓流量小
            DispatchRuleSortInterface handlerInstance5 = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.BLOCK_ORE_BUFFER_WAREHOUSE_ADDITION);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList5 = handlerInstance5.sortProcess(dispatchParameterReqDTOList4);
            // 将排序后的数据放入redis中
            cacheService.setString(DispatchConstant.REDIS_KEY+":"+WarehouseClassification.KKC, JSONUtil.toJsonStr(dispatchParameterReqDTOList5));
        } else {
            throw new RuntimeException("非块矿缓冲仓加仓，不支持该操作");
        }
    }

    /*
     *
     * 高炉返料
     * */
    @Override
    public void BlastFurnaceReturnMaterial() {
        WarehouseClassification preconfiguration = WarehouseClassification.GLFJFKC;
        if (preconfiguration.BlastFurnaceReturnMaterial()) {
            BasicStockBinReqDTO basicStockBinReqDTO = new BasicStockBinReqDTO();
            basicStockBinReqDTO.setBinCode(String.valueOf(WarehouseClassification.GLFJFKC));
            List<BasicStockBinRespVO> listBaseStockBin = FeignResultUtil.getDataFromBaseResponse(basicStockBinFeign.list(basicStockBinReqDTO));
            ArrayList<DispatchParameterReqDTO> parameterReqDTOArrayList = new ArrayList<>();
            // 根据起点设备来查看流程
            for (BasicStockBinRespVO basicStockBinRespVO : listBaseStockBin) {
                DispatchParameterReqDTO dispatchParameterReqDTO = new DispatchParameterReqDTO();
                List<FiveBasicInformationReqDTO> fiveBasicInformationReqDTOList = new ArrayList<>();
                FiveBasicInformationReqDTO fiveBasicInformationReqDTO = new FiveBasicInformationReqDTO();
                //根据起点设备查询流程
                FlowBasicReqDTO flowBasicReqDTO = new FlowBasicReqDTO();
                flowBasicReqDTO.setEndDeviceCode(basicStockBinRespVO.getDeviceOut());
                List<FlowBasicRespVO> flowBasicRespVOList = FeignResultUtil.getDataFromBaseResponse(flowBasicFeign.all(flowBasicReqDTO));
                // 起点仓
                dispatchParameterReqDTO.setSlot(basicStockBinRespVO);
                // 起点设备
                dispatchParameterReqDTO.setDeviceCodeList(flowBasicRespVOList.stream().map(FlowBasicRespVO::getStartDeviceCode).collect(Collectors.toList()));
                //起点设备默认值
                if (flowBasicRespVOList != null && flowBasicRespVOList.size() > 0) {
                    fiveBasicInformationReqDTO.setDeviceTypeDefault(flowBasicRespVOList.get(0).getStartDeviceCode());
                }
                for (FlowBasicRespVO flowBasicRespVO : flowBasicRespVOList) {
                    // 流程线路
                    fiveBasicInformationReqDTO.setFlow(flowBasicRespVO);
                }
                //终点设备
                fiveBasicInformationReqDTO.setDeviceCodeList(flowBasicRespVOList.stream().map(FlowBasicRespVO::getEndDeviceCode).collect(Collectors.toList()));
                //终点设备默认值
                if (flowBasicRespVOList != null && flowBasicRespVOList.size() > 0) {
                    fiveBasicInformationReqDTO.setDeviceTypeDefault(flowBasicRespVOList.get(0).getEndDeviceCode());
                }
                // 根据出仓设备来终点位置
                List<BasicStockBinRespVO> flowBasicList = null;
                BasicStockBinReqDTO basicStockBin = new BasicStockBinReqDTO();
                for (String s : fiveBasicInformationReqDTO.getDeviceCodeList()) {
                    basicStockBin.setDeviceIn(s);
                    flowBasicList = FeignResultUtil.getDataFromBaseResponse(basicStockBinFeign.list(basicStockBin));
                }
                // 终点位置
                fiveBasicInformationReqDTO.setOtherSlotList(flowBasicList);
                //仓标识
                dispatchParameterReqDTO.setSlotIdentification("2");
                fiveBasicInformationReqDTOList.add(fiveBasicInformationReqDTO);
                dispatchParameterReqDTO.setFlowList(fiveBasicInformationReqDTOList);
                parameterReqDTOArrayList.add(dispatchParameterReqDTO);
            }
            // 规则排序
            // 查看刮板机是否空闲
            DispatchRuleSortInterface handlerInstance1 = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.IS_THE_CAR_IDLE);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList1 = handlerInstance1.sortProcess(parameterReqDTOArrayList);
            //仓到达一定值返料
            DispatchRuleSortInterface handlerInstance2 = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.WAREHOUSE_RETURN_MATERIAL);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList2 = handlerInstance2.sortProcess(dispatchParameterReqDTOList1);
            // 将排序后的数据放入redis中
            cacheService.setString(DispatchConstant.REDIS_KEY+":"+WarehouseClassification.GLFJFKC, JSONUtil.toJsonStr(dispatchParameterReqDTOList2));
        } else {
            throw new RuntimeException("非焦粉仓返料，不支持该操作");
        }
    }


    /**
     *矿粉仓返料
     */
    @Override
    public void MineralPowderWarehouse() {
        WarehouseClassification preconfiguration = WarehouseClassification.KFC;
        if (preconfiguration.MineralPowderWarehouse()) {
            BasicStockBinReqDTO basicStockBinReqDTO = new BasicStockBinReqDTO();
            basicStockBinReqDTO.setBinCode(String.valueOf(WarehouseClassification.KFC));
            List<BasicStockBinRespVO> listBaseStockBin = FeignResultUtil.getDataFromBaseResponse(basicStockBinFeign.list(basicStockBinReqDTO));
            ArrayList<DispatchParameterReqDTO> parameterReqDTOArrayList = new ArrayList<>();
            // 根据起点设备来查看流程
            for (BasicStockBinRespVO basicStockBinRespVO : listBaseStockBin) {
                DispatchParameterReqDTO dispatchParameterReqDTO = new DispatchParameterReqDTO();
                List<FiveBasicInformationReqDTO> fiveBasicInformationReqDTOList = new ArrayList<>();
                FiveBasicInformationReqDTO fiveBasicInformationReqDTO = new FiveBasicInformationReqDTO();
                //根据起点设备查询流程
                FlowBasicReqDTO flowBasicReqDTO = new FlowBasicReqDTO();
                flowBasicReqDTO.setEndDeviceCode(basicStockBinRespVO.getDeviceOut());
                List<FlowBasicRespVO> flowBasicRespVOList = FeignResultUtil.getDataFromBaseResponse(flowBasicFeign.all(flowBasicReqDTO));
                // 起点仓
                dispatchParameterReqDTO.setSlot(basicStockBinRespVO);
                // 起点设备
                dispatchParameterReqDTO.setDeviceCodeList(flowBasicRespVOList.stream().map(FlowBasicRespVO::getStartDeviceCode).collect(Collectors.toList()));
                //起点设备默认值
                if (flowBasicRespVOList != null && flowBasicRespVOList.size() > 0) {
                    fiveBasicInformationReqDTO.setDeviceTypeDefault(flowBasicRespVOList.get(0).getStartDeviceCode());
                }
                for (FlowBasicRespVO flowBasicRespVO : flowBasicRespVOList) {
                    // 流程线路
                    fiveBasicInformationReqDTO.setFlow(flowBasicRespVO);
                }
                //终点设备
                fiveBasicInformationReqDTO.setDeviceCodeList(flowBasicRespVOList.stream().map(FlowBasicRespVO::getEndDeviceCode).collect(Collectors.toList()));
                //终点设备默认值
                if (flowBasicRespVOList != null && flowBasicRespVOList.size() > 0) {
                    fiveBasicInformationReqDTO.setDeviceTypeDefault(flowBasicRespVOList.get(0).getEndDeviceCode());
                }
                // 根据出仓设备来终点位置
                List<BasicStockBinRespVO> flowBasicList = null;
                BasicStockBinReqDTO basicStockBin = new BasicStockBinReqDTO();
                for (String s : fiveBasicInformationReqDTO.getDeviceCodeList()) {
                    basicStockBin.setDeviceIn(s);
                    flowBasicList = FeignResultUtil.getDataFromBaseResponse(basicStockBinFeign.list(basicStockBin));
                }
                // 终点位置
                fiveBasicInformationReqDTO.setOtherSlotList(flowBasicList);
                //仓标识
                dispatchParameterReqDTO.setSlotIdentification("2");
                fiveBasicInformationReqDTOList.add(fiveBasicInformationReqDTO);
                dispatchParameterReqDTO.setFlowList(fiveBasicInformationReqDTOList);
                parameterReqDTOArrayList.add(dispatchParameterReqDTO);
            }
            // 规则排序
            // 根据流程来进行排序
            DispatchRuleSortInterface handlerInstance = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.ROUTE_ENERGY_CONSUMPTION);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList = handlerInstance.sortProcess(parameterReqDTOArrayList);
            // 查看刮板机是否空闲
            DispatchRuleSortInterface handlerInstance1 = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.IS_THE_CAR_IDLE);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList1 = handlerInstance1.sortProcess(dispatchParameterReqDTOList);
            //仓到达一定值返料
            DispatchRuleSortInterface handlerInstance2 = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.WAREHOUSE_RETURN_MATERIAL);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList2 = handlerInstance2.sortProcess(dispatchParameterReqDTOList1);
            // 将排序后的数据放入redis中
            cacheService.setString(DispatchConstant.REDIS_KEY+":"+WarehouseClassification.KFC, JSONUtil.toJsonStr(parameterReqDTOArrayList));
        } else {
            throw new RuntimeException("非矿粉仓返料，不支持该操作");
        }
    }

    /**
     *
     * 焦粉仓返料
     * */
    @Override
    public void CokingPowderWarehouse() {
        WarehouseClassification preconfiguration = WarehouseClassification.JFC;
        if (preconfiguration.CokingPowderWarehouse()) {
            BasicStockBinReqDTO basicStockBinReqDTO = new BasicStockBinReqDTO();
            basicStockBinReqDTO.setBinCode(String.valueOf(WarehouseClassification.JFC));
            List<BasicStockBinRespVO> listBaseStockBin = FeignResultUtil.getDataFromBaseResponse(basicStockBinFeign.list(basicStockBinReqDTO));
            ArrayList<DispatchParameterReqDTO> parameterReqDTOArrayList = new ArrayList<>();
            // 根据起点设备来查看流程
            for (BasicStockBinRespVO basicStockBinRespVO : listBaseStockBin) {
                DispatchParameterReqDTO dispatchParameterReqDTO = new DispatchParameterReqDTO();
                List<FiveBasicInformationReqDTO> fiveBasicInformationReqDTOList = new ArrayList<>();
                FiveBasicInformationReqDTO fiveBasicInformationReqDTO = new FiveBasicInformationReqDTO();
                //根据起点设备查询流程
                FlowBasicReqDTO flowBasicReqDTO = new FlowBasicReqDTO();
                flowBasicReqDTO.setEndDeviceCode(basicStockBinRespVO.getDeviceOut());
                List<FlowBasicRespVO> flowBasicRespVOList = FeignResultUtil.getDataFromBaseResponse(flowBasicFeign.all(flowBasicReqDTO));
                // 起点仓
                dispatchParameterReqDTO.setSlot(basicStockBinRespVO);
                // 起点设备
                dispatchParameterReqDTO.setDeviceCodeList(flowBasicRespVOList.stream().map(FlowBasicRespVO::getStartDeviceCode).collect(Collectors.toList()));
                //起点设备默认值
                if (flowBasicRespVOList != null && flowBasicRespVOList.size() > 0) {
                    fiveBasicInformationReqDTO.setDeviceTypeDefault(flowBasicRespVOList.get(0).getStartDeviceCode());
                }
                for (FlowBasicRespVO flowBasicRespVO : flowBasicRespVOList) {
                    // 流程线路
                    fiveBasicInformationReqDTO.setFlow(flowBasicRespVO);
                }
                //终点设备
                fiveBasicInformationReqDTO.setDeviceCodeList(flowBasicRespVOList.stream().map(FlowBasicRespVO::getEndDeviceCode).collect(Collectors.toList()));
                //终点设备默认值
                if (flowBasicRespVOList != null && flowBasicRespVOList.size() > 0) {
                    fiveBasicInformationReqDTO.setDeviceTypeDefault(flowBasicRespVOList.get(0).getEndDeviceCode());
                }
                // 根据出仓设备来终点位置
                List<BasicStockBinRespVO> flowBasicList = null;
                BasicStockBinReqDTO basicStockBin = new BasicStockBinReqDTO();
                for (String s : fiveBasicInformationReqDTO.getDeviceCodeList()) {
                    basicStockBin.setDeviceIn(s);
                    flowBasicList = FeignResultUtil.getDataFromBaseResponse(basicStockBinFeign.list(basicStockBin));
                }
                // 终点位置
                fiveBasicInformationReqDTO.setOtherSlotList(flowBasicList);
                //仓标识
                dispatchParameterReqDTO.setSlotIdentification("2");
                fiveBasicInformationReqDTOList.add(fiveBasicInformationReqDTO);
                  dispatchParameterReqDTO.setFlowList(fiveBasicInformationReqDTOList);
                parameterReqDTOArrayList.add(dispatchParameterReqDTO);
            }
            // 规则排序
            // 查看刮板机是否空闲
            DispatchRuleSortInterface handlerInstance1 = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.IS_THE_CAR_IDLE);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList1 = handlerInstance1.sortProcess(parameterReqDTOArrayList);
            //仓到达一定值返料
            DispatchRuleSortInterface handlerInstance2 = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.WAREHOUSE_RETURN_MATERIAL);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList2 = handlerInstance2.sortProcess(dispatchParameterReqDTOList1);
            // 将排序后的数据放入redis中
            cacheService.setString(DispatchConstant.REDIS_KEY+":"+WarehouseClassification.JFC, JSONUtil.toJsonStr(dispatchParameterReqDTOList2));
        }else {
            throw new RuntimeException("非焦粉仓返料，不支持该操作");
        }
    }



    /**
     * 烧结燃料仓
     */
    @Override
    public void sinterBunker() {
        WarehouseClassification preconfiguration= WarehouseClassification.SJRLC;
        if (preconfiguration.sinterBunkerAdd()){
            BasicStockBinReqDTO basicStockBinReqDTO = new BasicStockBinReqDTO();
            basicStockBinReqDTO.setBinCode(String.valueOf(WarehouseClassification.SJRLC));
            List<BasicStockBinRespVO> listBaseStockBin = FeignResultUtil.getDataFromBaseResponse(basicStockBinFeign.list(basicStockBinReqDTO));
            ArrayList<DispatchParameterReqDTO> parameterReqDTOArrayList = new ArrayList<>();
            // 根据终点设备来查看流程
            for (BasicStockBinRespVO basicStockBinRespVO : listBaseStockBin) {
                    DispatchParameterReqDTO dispatchParameterReqDTO = new DispatchParameterReqDTO();
                    List<FiveBasicInformationReqDTO> fiveBasicInformationReqDTOList = new ArrayList<>();
                    FiveBasicInformationReqDTO fiveBasicInformationReqDTO = new FiveBasicInformationReqDTO();
                    // 根据出仓设备来查询流程
                    FlowBasicReqDTO flowBasicReqDTO = new FlowBasicReqDTO();
                    flowBasicReqDTO.setEndDeviceCode(basicStockBinRespVO.getDeviceIn());
                    List<FlowBasicRespVO> flowBasicRespVOList = FeignResultUtil.getDataFromBaseResponse(flowBasicFeign.all(flowBasicReqDTO));
                    // 终点仓
                    dispatchParameterReqDTO.setSlot(basicStockBinRespVO);
                    // 终点设备
                    dispatchParameterReqDTO.setDeviceCodeList(flowBasicRespVOList.stream().map(FlowBasicRespVO::getEndDeviceCode).collect(Collectors.toList()));
                    // 终点设备默认值
                    if (flowBasicRespVOList != null && flowBasicRespVOList.size() > 0) {
                        dispatchParameterReqDTO.setDeviceCodeDefault(flowBasicRespVOList.get(0).getEndDeviceCode());
                    }
                    for (FlowBasicRespVO flowBasicRespVO : flowBasicRespVOList) {
                        // 流程线路
                        fiveBasicInformationReqDTO.setFlow(flowBasicRespVO);
                    }
                    // 起点设备
                    fiveBasicInformationReqDTO.setDeviceCodeList(flowBasicRespVOList.stream().map(FlowBasicRespVO::getStartDeviceCode).collect(Collectors.toList()));
                    // 起点设备默认值
                    if(flowBasicRespVOList != null && flowBasicRespVOList.size() > 0){
                        fiveBasicInformationReqDTO.setDeviceTypeDefault(flowBasicRespVOList.get(0).getStartDeviceCode());
                    }
                    // 根据入仓设备来起点位置
                    List<BasicStockBinRespVO> flowBasicList = null;
                    BasicStockBinReqDTO basicStockBin = new BasicStockBinReqDTO();
                    for (String s : fiveBasicInformationReqDTO.getDeviceCodeList()) {
                        basicStockBin.setDeviceOut(s);
                        flowBasicList = FeignResultUtil.getDataFromBaseResponse(basicStockBinFeign.list(basicStockBin));
                    }
                    // 设备状态
                    dispatchParameterReqDTO.setState("0");
                    // 起点位置默认值
                    if (flowBasicList != null && flowBasicList.size() > 0) {
                        fiveBasicInformationReqDTO.setOtherSlotDefault(flowBasicList.get(0).getSlotName());
                    }
                    // 起点位置
                    fiveBasicInformationReqDTO.setOtherSlotList(flowBasicList);
                    // 仓标识
                    dispatchParameterReqDTO.setSlotIdentification("1");
                    fiveBasicInformationReqDTOList.add(fiveBasicInformationReqDTO);
                    dispatchParameterReqDTO.setFlowList(fiveBasicInformationReqDTOList);
                    parameterReqDTOArrayList.add(dispatchParameterReqDTO);
            }
            ArrayList<DispatchParameterReqDTO> dispatchParameterReqDTOS = new ArrayList<>();
            for (DispatchParameterReqDTO dispatchParameterReqDTO : parameterReqDTOArrayList) {
                for (FiveBasicInformationReqDTO fiveBasicInformationReqDTO : dispatchParameterReqDTO.getFlowList()) {
                    if (ObjectUtil.isNotEmpty(fiveBasicInformationReqDTO.getFlow())){
                        dispatchParameterReqDTOS.add(dispatchParameterReqDTO);
                    }
                }
            }
            // 根据流程来进行排序
            DispatchRuleSortInterface handlerInstance = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.ROUTE_ENERGY_CONSUMPTION);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList = handlerInstance.sortProcess(dispatchParameterReqDTOS);
            // 查看刮板机是否空闲
            DispatchRuleSortInterface handlerInstance1 = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.RULE_STARTING_POINT_EQUIPMENT);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList1 = handlerInstance1.sortProcess(dispatchParameterReqDTOList);
            // 查看起点位置的料
            DispatchRuleSortInterface handlerInstance2 = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.WAREHOUSE_MATERIALS);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList2 = handlerInstance2.sortProcess(dispatchParameterReqDTOList1);
            // 将排序后的数据放入redis中
            cacheService.setString(DispatchConstant.REDIS_KEY+":"+WarehouseClassification.SJRLC, JSONUtil.toJsonStr(dispatchParameterReqDTOList2));
        }else {
            throw new RuntimeException("非烧结燃料仓，不支持该操作");
        }
    }

    /**
     * 球团成品仓
     */
    @Override
    public void finishedPellet() {
        WarehouseClassification preconfiguration= WarehouseClassification.QTCPC;
        if (preconfiguration.finishedPellet()){
            BasicStockBinReqDTO basicStockBinReqDTO = new BasicStockBinReqDTO();
            basicStockBinReqDTO.setBinCode(String.valueOf(WarehouseClassification.QTCPC));
            List<BasicStockBinRespVO> listBaseStockBin = FeignResultUtil.getDataFromBaseResponse(basicStockBinFeign.list(basicStockBinReqDTO));
            List<DispatchParameterReqDTO> parameterReqDTOArrayList = new ArrayList<>();
            // 根据终点设备来查看流程
            for (BasicStockBinRespVO basicStockBinRespVO : listBaseStockBin) {
                DispatchParameterReqDTO dispatchParameterReqDTO = new DispatchParameterReqDTO();
                List<FiveBasicInformationReqDTO> fiveBasicInformationReqDTOList = new ArrayList<>();
                FiveBasicInformationReqDTO fiveBasicInformationReqDTO = new FiveBasicInformationReqDTO();
                // 根据出仓设备来查询流程
                FlowBasicReqDTO flowBasicReqDTO = new FlowBasicReqDTO();
                flowBasicReqDTO.setEndDeviceCode(basicStockBinRespVO.getDeviceIn());
                List<FlowBasicRespVO> flowBasicRespVOList = FeignResultUtil.getDataFromBaseResponse(flowBasicFeign.all(flowBasicReqDTO));
                // 终点仓
                dispatchParameterReqDTO.setSlot(basicStockBinRespVO);
                // 终点设备
                dispatchParameterReqDTO.setDeviceCodeList(flowBasicRespVOList.stream().map(FlowBasicRespVO::getEndDeviceCode).collect(Collectors.toList()));
                // 终点设备默认值
                if (flowBasicRespVOList != null && flowBasicRespVOList.size() > 0) {
                    dispatchParameterReqDTO.setDeviceCodeDefault(flowBasicRespVOList.get(0).getEndDeviceCode());
                }
                for (FlowBasicRespVO flowBasicRespVO : flowBasicRespVOList) {
                    // 流程线路
                    fiveBasicInformationReqDTO.setFlow(flowBasicRespVO);
                }
                // 起点设备
                fiveBasicInformationReqDTO.setDeviceCodeList(flowBasicRespVOList.stream().map(FlowBasicRespVO::getStartDeviceCode).collect(Collectors.toList()));
                // 起点设备默认值
                if(flowBasicRespVOList != null && flowBasicRespVOList.size() > 0){
                    fiveBasicInformationReqDTO.setDeviceTypeDefault(flowBasicRespVOList.get(0).getStartDeviceCode());
                }
                // 根据入仓设备来起点位置
                List<BasicStockBinRespVO> flowBasicList = null;
                BasicStockBinReqDTO basicStockBin = new BasicStockBinReqDTO();
                for (String s : fiveBasicInformationReqDTO.getDeviceCodeList()) {
                    basicStockBin.setDeviceOut(s);
                    flowBasicList = FeignResultUtil.getDataFromBaseResponse(basicStockBinFeign.list(basicStockBin));
                }
                // 起点位置
                fiveBasicInformationReqDTO.setOtherSlotList(flowBasicList);
                // 起点位置默认值
                if (flowBasicList != null && flowBasicList.size() > 0) {
                    fiveBasicInformationReqDTO.setOtherSlotDefault(flowBasicList.get(0).getSlotName());
                }
                // 设备状态
                dispatchParameterReqDTO.setState("0");
                // 仓标识
                dispatchParameterReqDTO.setSlotIdentification("1");
                fiveBasicInformationReqDTOList.add(fiveBasicInformationReqDTO);
                dispatchParameterReqDTO.setFlowList(fiveBasicInformationReqDTOList);
                parameterReqDTOArrayList.add(dispatchParameterReqDTO);
            }
            ArrayList<DispatchParameterReqDTO> dispatchParameterReqDTOS = new ArrayList<>();
            for (DispatchParameterReqDTO dispatchParameterReqDTO : parameterReqDTOArrayList) {
                for (FiveBasicInformationReqDTO fiveBasicInformationReqDTO : dispatchParameterReqDTO.getFlowList()) {
                    if (ObjectUtil.isNotEmpty(fiveBasicInformationReqDTO.getFlow())){
                        dispatchParameterReqDTOS.add(dispatchParameterReqDTO);
                    }
                }
            }
            // 根据流程的能耗和距离
            DispatchRuleSortInterface handlerInstance = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.ROUTE_ENERGY_CONSUMPTION);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList = handlerInstance.sortProcess(dispatchParameterReqDTOS);
            // 根据小车是否空闲
            DispatchRuleSortInterface handlerInstance1 = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.IS_THE_CAR_IDLE);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList1 = handlerInstance1.sortProcess(dispatchParameterReqDTOList);
            // 仓的可用时间
            DispatchRuleSortInterface handlerInstance2 = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.AVAILABLE_TIME);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList2 = handlerInstance2.sortProcess(dispatchParameterReqDTOList1);
            // 高炉运行先后
            DispatchRuleSortInterface handlerInstance3 = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.BLAST_FURNACE_OPERATION);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList3 = handlerInstance3.sortProcess(dispatchParameterReqDTOList2);
            // 不同的料进行区分
            DispatchRuleSortInterface handlerInstance4 = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.WAREHOUSE_MATERIALS);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList4 = handlerInstance4.sortProcess(dispatchParameterReqDTOList3);
            // 将排序后的数据放入redis中
            cacheService.setString(DispatchConstant.REDIS_KEY+":"+WarehouseClassification.QTCPC, JSONUtil.toJsonStr(dispatchParameterReqDTOList4));
        }else {
            throw new RuntimeException("非球团成品仓，不支持该操作");
        }
    }

    /**
     * 烧结成品仓
     */
    @Override
    public void sinteredProduct() {
        WarehouseClassification preconfiguration= WarehouseClassification.SJ34CPC;
        if (preconfiguration.sinteredProductAdd()){
            BasicStockBinReqDTO basicStockBinReqDTO = new BasicStockBinReqDTO();
            // 查出所有数据
            List<BasicStockBinRespVO> listBaseStockBin = FeignResultUtil.getDataFromBaseResponse(basicStockBinFeign.list(basicStockBinReqDTO));
            //根据终点仓来筛选
            listBaseStockBin = listBaseStockBin.stream().filter(record ->
                record.getBinCode().equals(WarehouseClassification.SJ34CPC.name())||
                        record.getBinCode().equals(WarehouseClassification.SJ2CPC.name())
            ).collect(Collectors.toList());
            ArrayList<DispatchParameterReqDTO> parameterReqDTOArrayList = new ArrayList<>();
            // 根据终点设备来查看流程
            for (BasicStockBinRespVO basicStockBinRespVO : listBaseStockBin) {
                DispatchParameterReqDTO dispatchParameterReqDTO = new DispatchParameterReqDTO();
                List<FiveBasicInformationReqDTO> fiveBasicInformationReqDTOList = new ArrayList<>();
                FiveBasicInformationReqDTO fiveBasicInformationReqDTO = new FiveBasicInformationReqDTO();
                // 根据出仓设备来查询流程
                FlowBasicReqDTO flowBasicReqDTO = new FlowBasicReqDTO();
                flowBasicReqDTO.setEndDeviceCode(basicStockBinRespVO.getDeviceIn());
                List<FlowBasicRespVO> flowBasicRespVOList = FeignResultUtil.getDataFromBaseResponse(flowBasicFeign.all(flowBasicReqDTO));
                // 终点仓
                dispatchParameterReqDTO.setSlot(basicStockBinRespVO);
                // 终点设备
                dispatchParameterReqDTO.setDeviceCodeList(flowBasicRespVOList.stream().map(FlowBasicRespVO::getEndDeviceCode).collect(Collectors.toList()));
                // 终点设备默认值
                if (flowBasicRespVOList != null && flowBasicRespVOList.size() > 0) {
                    dispatchParameterReqDTO.setDeviceCodeDefault(flowBasicRespVOList.get(0).getEndDeviceCode());
                }
                for (FlowBasicRespVO flowBasicRespVO : flowBasicRespVOList) {
                    // 流程线路
                    fiveBasicInformationReqDTO.setFlow(flowBasicRespVO);
                }
                // 起点设备
                fiveBasicInformationReqDTO.setDeviceCodeList(flowBasicRespVOList.stream().map(FlowBasicRespVO::getStartDeviceCode).collect(Collectors.toList()));
                // 起点设备默认值
                if(flowBasicRespVOList != null && flowBasicRespVOList.size() > 0){
                    fiveBasicInformationReqDTO.setDeviceTypeDefault(flowBasicRespVOList.get(0).getStartDeviceCode());
                }
                // 根据入仓设备来起点位置
                List<BasicStockBinRespVO> flowBasicList = null;
                BasicStockBinReqDTO basicStockBin = new BasicStockBinReqDTO();
                for (String s : fiveBasicInformationReqDTO.getDeviceCodeList()) {
                    basicStockBin.setDeviceOut(s);
                    flowBasicList = FeignResultUtil.getDataFromBaseResponse(basicStockBinFeign.list(basicStockBin));
                }
                // 起点位置
                fiveBasicInformationReqDTO.setOtherSlotList(flowBasicList);
                // 起点位置默认值
                if (flowBasicList != null && flowBasicList.size() > 0) {
                    fiveBasicInformationReqDTO.setOtherSlotDefault(flowBasicList.get(0).getSlotName());
                }
                // 设备状态
                dispatchParameterReqDTO.setState("0");
                // 仓标识
                dispatchParameterReqDTO.setSlotIdentification("1");
                fiveBasicInformationReqDTOList.add(fiveBasicInformationReqDTO);
                dispatchParameterReqDTO.setFlowList(fiveBasicInformationReqDTOList);
                parameterReqDTOArrayList.add(dispatchParameterReqDTO);
            }
            ArrayList<DispatchParameterReqDTO> dispatchParameterReqDTOS = new ArrayList<>();
            for (DispatchParameterReqDTO dispatchParameterReqDTO : parameterReqDTOArrayList) {
                for (FiveBasicInformationReqDTO fiveBasicInformationReqDTO : dispatchParameterReqDTO.getFlowList()) {
                    if (ObjectUtil.isNotEmpty(fiveBasicInformationReqDTO.getFlow())){
                        dispatchParameterReqDTOS.add(dispatchParameterReqDTO);
                    }
                }
            }
            // 仓的可用时间
            DispatchRuleSortInterface handlerInstance3 = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.AVAILABLE_TIME);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList3 = handlerInstance3.sortProcess(dispatchParameterReqDTOS);
            // 根据流程的能耗和距离
            DispatchRuleSortInterface handlerInstance = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.ROUTE_ENERGY_CONSUMPTION);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList = handlerInstance.sortProcess(dispatchParameterReqDTOList3);
            // 小车是否空闲
            DispatchRuleSortInterface handlerInstance1 = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.IS_THE_CAR_IDLE);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList2 = handlerInstance1.sortProcess(dispatchParameterReqDTOList);
            // 高炉运行先后
            DispatchRuleSortInterface handlerInstance4 = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.BLAST_FURNACE_OPERATION);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList4 = handlerInstance4.sortProcess(dispatchParameterReqDTOList2);
            // 将排序后的数据放入redis中
            cacheService.setString(DispatchConstant.REDIS_KEY+":"+WarehouseClassification.SJ34CPC, JSONUtil.toJsonStr(dispatchParameterReqDTOList4));
        }else {
            throw new RuntimeException("非烧结成品仓，不支持该操作");
        }
    }

    /**
     * 球团供料加仓
     */

    public List<DispatchParameterReqDTO> isEmpty(List<DispatchParameterReqDTO> parameterReqDTOArrayList) {
        ArrayList<DispatchParameterReqDTO> dispatchParameterReqDTOS = new ArrayList<>();
        for (DispatchParameterReqDTO dispatchParameterReqDTO : parameterReqDTOArrayList) {
            for (FiveBasicInformationReqDTO fiveBasicInformationReqDTO : dispatchParameterReqDTO.getFlowList()) {
                if (ObjectUtil.isNotEmpty(fiveBasicInformationReqDTO.getFlow())){
                    dispatchParameterReqDTOS.add(dispatchParameterReqDTO);
                }
            }
        }
        return dispatchParameterReqDTOS;
    }
    @Override
    public void dispatchBallGroup() {
        WarehouseClassification classification = WarehouseClassification.QTPLC;
        if (classification.BallAdd()) {
            BasicStockBinReqDTO basicStockBinReqDTO = new BasicStockBinReqDTO();
            basicStockBinReqDTO.setBinCode(String.valueOf(WarehouseClassification.QTPLC));
            List<BasicStockBinRespVO> listBaseStockBin = FeignResultUtil.getDataFromBaseResponse(basicStockBinFeign.list(basicStockBinReqDTO));
            List<DispatchParameterReqDTO> parameterReqDTOArrayList = new ArrayList<>();
            // 根据终点设备来查看流程
            for (BasicStockBinRespVO basicStockBinRespVO : listBaseStockBin) {
                DispatchParameterReqDTO dispatchParameterReqDTO = new DispatchParameterReqDTO();
                List<FiveBasicInformationReqDTO> fiveBasicInformationReqDTOList = new ArrayList<>();
                FiveBasicInformationReqDTO fiveBasicInformationReqDTO = new FiveBasicInformationReqDTO();
                // 根据出仓设备来查询流程
                FlowBasicReqDTO flowBasicReqDTO = new FlowBasicReqDTO();
                flowBasicReqDTO.setEndDeviceCode(basicStockBinRespVO.getDeviceIn());
                List<FlowBasicRespVO> flowBasicRespVOList = FeignResultUtil.getDataFromBaseResponse(flowBasicFeign.all(flowBasicReqDTO));
                // 终点仓
                dispatchParameterReqDTO.setSlot(basicStockBinRespVO);
                // 终点设备
                dispatchParameterReqDTO.setDeviceCodeList(flowBasicRespVOList.stream().map(FlowBasicRespVO::getEndDeviceCode).collect(Collectors.toList()));
                // 终点设备默认值
                if (flowBasicRespVOList != null && flowBasicRespVOList.size() > 0) {
                    dispatchParameterReqDTO.setDeviceCodeDefault(flowBasicRespVOList.get(0).getEndDeviceCode());
                }
                for (FlowBasicRespVO flowBasicRespVO : flowBasicRespVOList) {
                    // 流程线路
                    fiveBasicInformationReqDTO.setFlow(flowBasicRespVO);
                }
                // 起点设备
                fiveBasicInformationReqDTO.setDeviceCodeList(flowBasicRespVOList.stream().map(FlowBasicRespVO::getStartDeviceCode).collect(Collectors.toList()));
                // 起点设备默认值
                if(flowBasicRespVOList != null && flowBasicRespVOList.size() > 0){
                    fiveBasicInformationReqDTO.setDeviceTypeDefault(flowBasicRespVOList.get(0).getStartDeviceCode());
                }
                // 根据入仓设备来起点位置
                List<BasicStockBinRespVO> flowBasicList = null;
                BasicStockBinReqDTO basicStockBin = new BasicStockBinReqDTO();
                for (String s : fiveBasicInformationReqDTO.getDeviceCodeList()) {
                    basicStockBin.setDeviceOut(s);
                    flowBasicList = FeignResultUtil.getDataFromBaseResponse(basicStockBinFeign.list(basicStockBin));
                }
                // 设备状态
                dispatchParameterReqDTO.setState("0");
                // 起点位置默认值
                if (flowBasicList != null && flowBasicList.size() > 0) {
                    fiveBasicInformationReqDTO.setOtherSlotDefault(flowBasicList.get(0).getSlotName());
                }
                // 起点位置
                fiveBasicInformationReqDTO.setOtherSlotList(flowBasicList);
                // 仓标识
                dispatchParameterReqDTO.setSlotIdentification("1");
                fiveBasicInformationReqDTOList.add(fiveBasicInformationReqDTO);
                dispatchParameterReqDTO.setFlowList(fiveBasicInformationReqDTOList);
                parameterReqDTOArrayList.add(dispatchParameterReqDTO);
            }
            // 规则排序
            List<DispatchParameterReqDTO> empty = isEmpty(parameterReqDTOArrayList);
            //根据物料类型
            DispatchRuleSortInterface handlerInstance = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.WAREHOUSE_MATERIALS);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList = handlerInstance.sortProcess(empty);
            //根据料仓可用时间
            DispatchRuleSortInterface handlerInstance2 = dispatchRuleSortFactory.getHandlerInstance(RuleCodeConstant.AVAILABLE_TIME);
            dispatchParameterReqDTOList = handlerInstance2.sortProcess(dispatchParameterReqDTOList);
            //根据刮板机走行时间  @todo
            cacheService.setString(DispatchConstant.REDIS_KEY + ":QTPLC", JSONUtil.toJsonStr(dispatchParameterReqDTOList));
        } else {
            throw new RuntimeException("非球团供料加仓，不支持该操作");
        }
    }


    //2、3、4#烧结供料加仓规则排序
    public List<DispatchParameterReqDTO> sort(List<DispatchParameterReqDTO> data){
        List<String> list = Arrays.asList(RuleCodeConstant.IS_THE_CAR_IDLE,RuleCodeConstant.WAREHOUSE_MATERIALS, RuleCodeConstant.AVAILABLE_TIME, RuleCodeConstant.MATERIAL_INVENTORY, RuleCodeConstant.ROUTE_ENERGY_CONSUMPTION);
        for (String s : list) {
            DispatchRuleSortInterface handlerInstance = dispatchRuleSortFactory.getHandlerInstance(s);
            handlerInstance.sortProcess(data);
        }
        return data;
    }
    /**
     * 2#烧结供料加仓
     */
    @Override
    public void dispatch2SinterFeed() {
        WarehouseClassification classification = WarehouseClassification.SJ2PLC;
        if (classification.SinterAdd()) {
            BasicStockBinReqDTO basicStockBinReqDTO = new BasicStockBinReqDTO();
            basicStockBinReqDTO.setBinCode(String.valueOf(WarehouseClassification.SJ2PLC));
            List<BasicStockBinRespVO> listBaseStockBin = FeignResultUtil.getDataFromBaseResponse(basicStockBinFeign.list(basicStockBinReqDTO));
            ArrayList<DispatchParameterReqDTO> parameterReqDTOArrayList = new ArrayList<>();
            // 根据终点设备来查看流程
            for (BasicStockBinRespVO basicStockBinRespVO : listBaseStockBin) {
                DispatchParameterReqDTO dispatchParameterReqDTO = new DispatchParameterReqDTO();
                List<FiveBasicInformationReqDTO> fiveBasicInformationReqDTOList = new ArrayList<>();
                FiveBasicInformationReqDTO fiveBasicInformationReqDTO = new FiveBasicInformationReqDTO();
                // 根据出仓设备来查询流程
                FlowBasicReqDTO flowBasicReqDTO = new FlowBasicReqDTO();
                flowBasicReqDTO.setEndDeviceCode(basicStockBinRespVO.getDeviceIn());
                List<FlowBasicRespVO> flowBasicRespVOList = FeignResultUtil.getDataFromBaseResponse(flowBasicFeign.all(flowBasicReqDTO));
                // 终点仓
                dispatchParameterReqDTO.setSlot(basicStockBinRespVO);
                // 终点设备
                dispatchParameterReqDTO.setDeviceCodeList(flowBasicRespVOList.stream().map(FlowBasicRespVO::getEndDeviceCode).collect(Collectors.toList()));
                // 终点设备默认值
                if (flowBasicRespVOList != null && flowBasicRespVOList.size() > 0) {
                    dispatchParameterReqDTO.setDeviceCodeDefault(flowBasicRespVOList.get(0).getEndDeviceCode());
                }
                for (FlowBasicRespVO flowBasicRespVO : flowBasicRespVOList) {
                    // 流程线路
                    fiveBasicInformationReqDTO.setFlow(flowBasicRespVO);
                }
                // 起点设备
                fiveBasicInformationReqDTO.setDeviceCodeList(flowBasicRespVOList.stream().map(FlowBasicRespVO::getStartDeviceCode).collect(Collectors.toList()));
                // 起点设备默认值
                if(flowBasicRespVOList != null && flowBasicRespVOList.size() > 0){
                    fiveBasicInformationReqDTO.setDeviceTypeDefault(flowBasicRespVOList.get(0).getStartDeviceCode());
                }
                // 根据入仓设备来起点位置
                List<BasicStockBinRespVO> flowBasicList = null;
                BasicStockBinReqDTO basicStockBin = new BasicStockBinReqDTO();
                for (String s : fiveBasicInformationReqDTO.getDeviceCodeList()) {
                    basicStockBin.setDeviceOut(s);
                    flowBasicList = FeignResultUtil.getDataFromBaseResponse(basicStockBinFeign.list(basicStockBin));
                }
                // 设备状态
                dispatchParameterReqDTO.setState("0");
                // 起点位置默认值
                if (flowBasicList != null && flowBasicList.size() > 0) {
                    fiveBasicInformationReqDTO.setOtherSlotDefault(flowBasicList.get(0).getSlotName());
                }
                // 起点位置
                fiveBasicInformationReqDTO.setOtherSlotList(flowBasicList);
                // 仓标识
                dispatchParameterReqDTO.setSlotIdentification("1");
                fiveBasicInformationReqDTOList.add(fiveBasicInformationReqDTO);
                dispatchParameterReqDTO.setFlowList(fiveBasicInformationReqDTOList);
                parameterReqDTOArrayList.add(dispatchParameterReqDTO);
            }
//          // 规则排序
            List<DispatchParameterReqDTO> empty = isEmpty(parameterReqDTOArrayList);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList = sort(empty);
            cacheService.setString(DispatchConstant.REDIS_KEY + ":SJ2PLC", JSONUtil.toJsonStr(dispatchParameterReqDTOList));
        } else {
            throw new RuntimeException("非2#烧结供料加仓，不支持该操作");
        }
    }


    /**
     * 3#烧结供料加仓
     */
    @Override
    public void dispatch3SinterFeed() {
        WarehouseClassification classification = WarehouseClassification.SJ3PLC;
        if (classification.SinterAdd()) {
            BasicStockBinReqDTO basicStockBinReqDTO = new BasicStockBinReqDTO();
            basicStockBinReqDTO.setBinCode(String.valueOf(WarehouseClassification.SJ3PLC));
            List<BasicStockBinRespVO> listBaseStockBin = FeignResultUtil.getDataFromBaseResponse(basicStockBinFeign.list(basicStockBinReqDTO));
            ArrayList<DispatchParameterReqDTO> parameterReqDTOArrayList = new ArrayList<>();
            // 根据终点设备来查看流程
            for (BasicStockBinRespVO basicStockBinRespVO : listBaseStockBin) {
                DispatchParameterReqDTO dispatchParameterReqDTO = new DispatchParameterReqDTO();
                List<FiveBasicInformationReqDTO> fiveBasicInformationReqDTOList = new ArrayList<>();
                FiveBasicInformationReqDTO fiveBasicInformationReqDTO = new FiveBasicInformationReqDTO();
                // 根据出仓设备来查询流程
                FlowBasicReqDTO flowBasicReqDTO = new FlowBasicReqDTO();
                flowBasicReqDTO.setEndDeviceCode(basicStockBinRespVO.getDeviceIn());
                List<FlowBasicRespVO> flowBasicRespVOList = FeignResultUtil.getDataFromBaseResponse(flowBasicFeign.all(flowBasicReqDTO));
                // 终点仓
                dispatchParameterReqDTO.setSlot(basicStockBinRespVO);
                // 终点设备
                dispatchParameterReqDTO.setDeviceCodeList(flowBasicRespVOList.stream().map(FlowBasicRespVO::getEndDeviceCode).collect(Collectors.toList()));
                // 终点设备默认值
                if (flowBasicRespVOList != null && flowBasicRespVOList.size() > 0) {
                    dispatchParameterReqDTO.setDeviceCodeDefault(flowBasicRespVOList.get(0).getEndDeviceCode());
                }
                for (FlowBasicRespVO flowBasicRespVO : flowBasicRespVOList) {
                    // 流程线路
                    fiveBasicInformationReqDTO.setFlow(flowBasicRespVO);
                }
                // 起点设备
                fiveBasicInformationReqDTO.setDeviceCodeList(flowBasicRespVOList.stream().map(FlowBasicRespVO::getStartDeviceCode).collect(Collectors.toList()));
                // 起点设备默认值
                if(flowBasicRespVOList != null && flowBasicRespVOList.size() > 0){
                    fiveBasicInformationReqDTO.setDeviceTypeDefault(flowBasicRespVOList.get(0).getStartDeviceCode());
                }
                // 根据入仓设备来起点位置
                List<BasicStockBinRespVO> flowBasicList = null;
                BasicStockBinReqDTO basicStockBin = new BasicStockBinReqDTO();
                for (String s : fiveBasicInformationReqDTO.getDeviceCodeList()) {
                    basicStockBin.setDeviceOut(s);
                    flowBasicList = FeignResultUtil.getDataFromBaseResponse(basicStockBinFeign.list(basicStockBin));
                }
                // 设备状态
                dispatchParameterReqDTO.setState("0");
                // 起点位置默认值
                if (flowBasicList != null && flowBasicList.size() > 0) {
                    fiveBasicInformationReqDTO.setOtherSlotDefault(flowBasicList.get(0).getSlotName());
                }
                // 起点位置
                fiveBasicInformationReqDTO.setOtherSlotList(flowBasicList);
                // 仓标识
                dispatchParameterReqDTO.setSlotIdentification("1");
                fiveBasicInformationReqDTOList.add(fiveBasicInformationReqDTO);
                dispatchParameterReqDTO.setFlowList(fiveBasicInformationReqDTOList);
                parameterReqDTOArrayList.add(dispatchParameterReqDTO);
            }
            // 规则排序
            List<DispatchParameterReqDTO> empty = isEmpty(parameterReqDTOArrayList);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList = sort(empty);
            cacheService.setString(DispatchConstant.REDIS_KEY + ":SJ3PLC", JSONUtil.toJsonStr(dispatchParameterReqDTOList));
        } else {
            throw new RuntimeException("非3#烧结供料加仓，不支持该操作");
        }
    }


    /**
     * 4#烧结供料加仓
     */
    @Override
    public void dispatch4SinterFeed() {
        WarehouseClassification classification = WarehouseClassification.SJ4PLC;
        if (classification.SinterAdd()) {
            BasicStockBinReqDTO basicStockBinReqDTO = new BasicStockBinReqDTO();
            basicStockBinReqDTO.setBinCode(String.valueOf(WarehouseClassification.SJ4PLC));
            List<BasicStockBinRespVO> listBaseStockBin = FeignResultUtil.getDataFromBaseResponse(basicStockBinFeign.list(basicStockBinReqDTO));
            ArrayList<DispatchParameterReqDTO> parameterReqDTOArrayList = new ArrayList<>();
            // 根据终点设备来查看流程
            for (BasicStockBinRespVO basicStockBinRespVO : listBaseStockBin) {
                DispatchParameterReqDTO dispatchParameterReqDTO = new DispatchParameterReqDTO();
                List<FiveBasicInformationReqDTO> fiveBasicInformationReqDTOList = new ArrayList<>();
                FiveBasicInformationReqDTO fiveBasicInformationReqDTO = new FiveBasicInformationReqDTO();
                // 根据出仓设备来查询流程
                FlowBasicReqDTO flowBasicReqDTO = new FlowBasicReqDTO();
                flowBasicReqDTO.setEndDeviceCode(basicStockBinRespVO.getDeviceIn());
                List<FlowBasicRespVO> flowBasicRespVOList = FeignResultUtil.getDataFromBaseResponse(flowBasicFeign.all(flowBasicReqDTO));
                // 终点仓
                dispatchParameterReqDTO.setSlot(basicStockBinRespVO);
                // 终点设备
                dispatchParameterReqDTO.setDeviceCodeList(flowBasicRespVOList.stream().map(FlowBasicRespVO::getEndDeviceCode).collect(Collectors.toList()));
                // 终点设备默认值
                if (flowBasicRespVOList != null && flowBasicRespVOList.size() > 0) {
                    dispatchParameterReqDTO.setDeviceCodeDefault(flowBasicRespVOList.get(0).getEndDeviceCode());
                }
                for (FlowBasicRespVO flowBasicRespVO : flowBasicRespVOList) {
                    // 流程线路
                    fiveBasicInformationReqDTO.setFlow(flowBasicRespVO);
                }
                // 起点设备
                fiveBasicInformationReqDTO.setDeviceCodeList(flowBasicRespVOList.stream().map(FlowBasicRespVO::getStartDeviceCode).collect(Collectors.toList()));
                // 起点设备默认值
                if(flowBasicRespVOList != null && flowBasicRespVOList.size() > 0){
                    fiveBasicInformationReqDTO.setDeviceTypeDefault(flowBasicRespVOList.get(0).getStartDeviceCode());
                }
                // 根据入仓设备来起点位置
                List<BasicStockBinRespVO> flowBasicList = null;
                BasicStockBinReqDTO basicStockBin = new BasicStockBinReqDTO();
                for (String s : fiveBasicInformationReqDTO.getDeviceCodeList()) {
                    basicStockBin.setDeviceOut(s);
                    flowBasicList = FeignResultUtil.getDataFromBaseResponse(basicStockBinFeign.list(basicStockBin));
                }
                // 设备状态
                dispatchParameterReqDTO.setState("0");
                // 起点位置默认值
                if (flowBasicList != null && flowBasicList.size() > 0) {
                    fiveBasicInformationReqDTO.setOtherSlotDefault(flowBasicList.get(0).getSlotName());
                }
                // 起点位置
                fiveBasicInformationReqDTO.setOtherSlotList(flowBasicList);
                // 仓标识
                dispatchParameterReqDTO.setSlotIdentification("1");
                fiveBasicInformationReqDTOList.add(fiveBasicInformationReqDTO);
                dispatchParameterReqDTO.setFlowList(fiveBasicInformationReqDTOList);
                parameterReqDTOArrayList.add(dispatchParameterReqDTO);
            }
            // 规则排序
            List<DispatchParameterReqDTO> empty = isEmpty(parameterReqDTOArrayList);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList = sort(empty);
            cacheService.setString(DispatchConstant.REDIS_KEY + ":SJ4PLC", JSONUtil.toJsonStr(dispatchParameterReqDTOList));
        } else {
            throw new RuntimeException("非4#烧结供料加仓，不支持该操作");
        }
    }


    //白云石、石灰石供料加仓规则排序
    public List<DispatchParameterReqDTO> sort2(List<DispatchParameterReqDTO> data){
        List<String> list = Arrays.asList( RuleCodeConstant.IS_THE_CAR_IDLE,RuleCodeConstant.WAREHOUSE_MATERIALS, RuleCodeConstant.MATERIAL_INVENTORY, RuleCodeConstant.ROUTE_ENERGY_CONSUMPTION);
        for (String s : list) {
            DispatchRuleSortInterface handlerInstance = dispatchRuleSortFactory.getHandlerInstance(s);
            handlerInstance.sortProcess(data);
        }
        return data;
    }
    /**
     * 白云石仓加仓
     */
    @Override
    public void dispatchBYS() {
        WarehouseClassification classification = WarehouseClassification.BYSC;
        if (classification.BYSAdd()) {
            BasicStockBinReqDTO basicStockBinReqDTO = new BasicStockBinReqDTO();
            basicStockBinReqDTO.setBinCode(String.valueOf(WarehouseClassification.BYSC));
            List<BasicStockBinRespVO> listBaseStockBin = FeignResultUtil.getDataFromBaseResponse(basicStockBinFeign.list(basicStockBinReqDTO));
            ArrayList<DispatchParameterReqDTO> parameterReqDTOArrayList = new ArrayList<>();
            // 根据终点设备来查看流程
            for (BasicStockBinRespVO basicStockBinRespVO : listBaseStockBin) {
                DispatchParameterReqDTO dispatchParameterReqDTO = new DispatchParameterReqDTO();
                List<FiveBasicInformationReqDTO> fiveBasicInformationReqDTOList = new ArrayList<>();
                FiveBasicInformationReqDTO fiveBasicInformationReqDTO = new FiveBasicInformationReqDTO();
                // 根据出仓设备来查询流程
                FlowBasicReqDTO flowBasicReqDTO = new FlowBasicReqDTO();
                flowBasicReqDTO.setEndDeviceCode(basicStockBinRespVO.getDeviceIn());
                List<FlowBasicRespVO> flowBasicRespVOList = FeignResultUtil.getDataFromBaseResponse(flowBasicFeign.all(flowBasicReqDTO));
                // 终点仓
                dispatchParameterReqDTO.setSlot(basicStockBinRespVO);
                // 终点设备
                dispatchParameterReqDTO.setDeviceCodeList(flowBasicRespVOList.stream().map(FlowBasicRespVO::getEndDeviceCode).collect(Collectors.toList()));
                // 终点设备默认值
                if (flowBasicRespVOList != null && flowBasicRespVOList.size() > 0) {
                    dispatchParameterReqDTO.setDeviceCodeDefault(flowBasicRespVOList.get(0).getEndDeviceCode());
                }
                for (FlowBasicRespVO flowBasicRespVO : flowBasicRespVOList) {
                    // 流程线路
                    fiveBasicInformationReqDTO.setFlow(flowBasicRespVO);
                }
                // 起点设备
                fiveBasicInformationReqDTO.setDeviceCodeList(flowBasicRespVOList.stream().map(FlowBasicRespVO::getStartDeviceCode).collect(Collectors.toList()));
                // 起点设备默认值
                if(flowBasicRespVOList != null && flowBasicRespVOList.size() > 0){
                    fiveBasicInformationReqDTO.setDeviceTypeDefault(flowBasicRespVOList.get(0).getStartDeviceCode());
                }
                // 根据入仓设备来起点位置
                List<BasicStockBinRespVO> flowBasicList = null;
                BasicStockBinReqDTO basicStockBin = new BasicStockBinReqDTO();
                for (String s : fiveBasicInformationReqDTO.getDeviceCodeList()) {
                    basicStockBin.setDeviceOut(s);
                    flowBasicList = FeignResultUtil.getDataFromBaseResponse(basicStockBinFeign.list(basicStockBin));
                }
                // 设备状态
                dispatchParameterReqDTO.setState("0");
                // 起点位置默认值
                if (flowBasicList != null && flowBasicList.size() > 0) {
                    fiveBasicInformationReqDTO.setOtherSlotDefault(flowBasicList.get(0).getSlotName());
                }
                // 起点位置
                fiveBasicInformationReqDTO.setOtherSlotList(flowBasicList);
                // 仓标识
                dispatchParameterReqDTO.setSlotIdentification("1");
                fiveBasicInformationReqDTOList.add(fiveBasicInformationReqDTO);
                dispatchParameterReqDTO.setFlowList(fiveBasicInformationReqDTOList);
                parameterReqDTOArrayList.add(dispatchParameterReqDTO);
            }
            // 规则排序
            List<DispatchParameterReqDTO> empty = isEmpty(parameterReqDTOArrayList);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList = sort2(empty);
            cacheService.setString(DispatchConstant.REDIS_KEY + ":BYSC", JSONUtil.toJsonStr(dispatchParameterReqDTOList));
        } else {
            throw new RuntimeException("非白云石仓，不支持该操作");
        }
    }


    /**
     * 石灰石仓加仓
     */
    @Override
    public void dispatchSHS() {
        WarehouseClassification classification = WarehouseClassification.SHSC;
        if (classification.SHSAdd()) {
            BasicStockBinReqDTO basicStockBinReqDTO = new BasicStockBinReqDTO();
            basicStockBinReqDTO.setBinCode(String.valueOf(WarehouseClassification.SHSC));
            List<BasicStockBinRespVO> listBaseStockBin = FeignResultUtil.getDataFromBaseResponse(basicStockBinFeign.list(basicStockBinReqDTO));
            ArrayList<DispatchParameterReqDTO> parameterReqDTOArrayList = new ArrayList<>();
            // 根据终点设备来查看流程
            for (BasicStockBinRespVO basicStockBinRespVO : listBaseStockBin) {
                DispatchParameterReqDTO dispatchParameterReqDTO = new DispatchParameterReqDTO();
                List<FiveBasicInformationReqDTO> fiveBasicInformationReqDTOList = new ArrayList<>();
                FiveBasicInformationReqDTO fiveBasicInformationReqDTO = new FiveBasicInformationReqDTO();
                // 根据出仓设备来查询流程
                FlowBasicReqDTO flowBasicReqDTO = new FlowBasicReqDTO();
                flowBasicReqDTO.setEndDeviceCode(basicStockBinRespVO.getDeviceIn());
                List<FlowBasicRespVO> flowBasicRespVOList = FeignResultUtil.getDataFromBaseResponse(flowBasicFeign.all(flowBasicReqDTO));
                // 终点仓
                dispatchParameterReqDTO.setSlot(basicStockBinRespVO);
                // 终点设备
                dispatchParameterReqDTO.setDeviceCodeList(flowBasicRespVOList.stream().map(FlowBasicRespVO::getEndDeviceCode).collect(Collectors.toList()));
                // 终点设备默认值
                if (flowBasicRespVOList != null && flowBasicRespVOList.size() > 0) {
                    dispatchParameterReqDTO.setDeviceCodeDefault(flowBasicRespVOList.get(0).getEndDeviceCode());
                }
                for (FlowBasicRespVO flowBasicRespVO : flowBasicRespVOList) {
                    // 流程线路
                    fiveBasicInformationReqDTO.setFlow(flowBasicRespVO);
                }
                // 起点设备
                fiveBasicInformationReqDTO.setDeviceCodeList(flowBasicRespVOList.stream().map(FlowBasicRespVO::getStartDeviceCode).collect(Collectors.toList()));
                // 起点设备默认值
                if(flowBasicRespVOList != null && flowBasicRespVOList.size() > 0){
                    fiveBasicInformationReqDTO.setDeviceTypeDefault(flowBasicRespVOList.get(0).getStartDeviceCode());
                }
                // 根据入仓设备来起点位置
                List<BasicStockBinRespVO> flowBasicList = null;
                BasicStockBinReqDTO basicStockBin = new BasicStockBinReqDTO();
                for (String s : fiveBasicInformationReqDTO.getDeviceCodeList()) {
                    basicStockBin.setDeviceOut(s);
                    flowBasicList = FeignResultUtil.getDataFromBaseResponse(basicStockBinFeign.list(basicStockBin));
                }
                // 设备状态
                dispatchParameterReqDTO.setState("0");
                // 起点位置默认值
                if (flowBasicList != null && flowBasicList.size() > 0) {
                    fiveBasicInformationReqDTO.setOtherSlotDefault(flowBasicList.get(0).getSlotName());
                }
                // 起点位置
                fiveBasicInformationReqDTO.setOtherSlotList(flowBasicList);
                // 仓标识
                dispatchParameterReqDTO.setSlotIdentification("1");
                fiveBasicInformationReqDTOList.add(fiveBasicInformationReqDTO);
                dispatchParameterReqDTO.setFlowList(fiveBasicInformationReqDTOList);
                parameterReqDTOArrayList.add(dispatchParameterReqDTO);
            }
            // 规则排序
            List<DispatchParameterReqDTO> empty = isEmpty(parameterReqDTOArrayList);
            List<DispatchParameterReqDTO> dispatchParameterReqDTOList = sort2(empty);
            cacheService.setString(DispatchConstant.REDIS_KEY + ":SHSC", JSONUtil.toJsonStr(dispatchParameterReqDTOList));
        } else {
            throw new RuntimeException("非石灰石仓，不支持该操作");
        }
    }
}
